import java.util.ArrayList;
import java.util.Stack;

/*
* 输入一个链表的头节点，按链表从尾到头的顺序返回每个节点的值（用数组返回）。
* */
public class JZ6 {



    public static ArrayList<Integer> printListFromTailToHead(ListNode listNode) {

        ArrayList<Integer> arrayList = new ArrayList<>();
        Stack<Integer> stack = new Stack<>();

        ListNode p = listNode;

        while(p!=null){
            stack.push(p.val);
            p=p.next;
        }

        while(!stack.empty()){
            arrayList.add(stack.pop());
        }

        return arrayList;
    }


    public static void useStack(ListNode head){

        ListNode p = head;

        Integer stack[] = new Integer[10];
        int index = 0;
        int time=0;
        if(head==null)
            return;
        else{
            while(p!=null){
                //入栈
                stack[index]=p.val;
                index++;
                p=p.next;
            }

            System.out.println("time is "+time);
            //打印出栈
            for(int i = 0 ; i < index;i++){
                System.out.println(stack[i]);
            }

        }
    }

    public static void digui(ListNode head){
        if(head!=null){
            digui(head.next);
            System.out.println(head.val);
        }
    }
}




